﻿using HDS.Data.MongoDB;
using HDS.IService.Log;
using HDS.Model;
using HDS.Model.Entity.Log;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace HDS.Service.Log
{
    public class ApiLogService : IApiLogService
    {
        private MongoDbContext dbContext = new MongoDbContext("Vhp", "api_log");

        public async Task Add(ApiLog entity, DateTime requestTime)
        {
            var collectionName = $"search_{requestTime.ToString("yyyyMMdd")}";
            if (!string.IsNullOrEmpty(entity.RatePlanId))
                collectionName = $"confirm_{requestTime.ToString("yyyyMM")}";
            if (!string.IsNullOrEmpty(entity.OrderId))
                collectionName = $"order_{requestTime.ToString("yyyyMM")}";

            entity.Id = Guid.NewGuid().ToString();
            entity.Node = Dns.GetHostName();
            var collection = dbContext.GetCollection<ApiLog>(collectionName);
            await collection.InsertOneAsync(entity);
        }

        public Task<DataPagingModel<ApiLog>> GetList(Expression<Func<ApiLog, bool>> whereExpression)
        {
            throw new NotImplementedException();
        }
    }
}
